package com.ruoyi.web.controller.map;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.map.domain.BuildingInfo;
import com.ruoyi.map.domain.UnitInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.map.domain.ApplyInvestigation;
import com.ruoyi.map.service.IApplyInvestigationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 申请调查Controller
 *
 * @author dihang
 * @date 2023-08-16
 */
@Api(value = "小程序申请调查", tags = {"小程序申请调查"})
@RestController
@RequestMapping("/map/investigation")
public class ApplyInvestigationController extends BaseController {
    @Autowired
    private IApplyInvestigationService applyInvestigationService;

    /**
     * 查询申请调查列表
     */
    @ApiOperation(value = "查看申请调查列表")
//    @PreAuthorize("@ss.hasPermi('map:investigation:list')")
    @GetMapping("/list")
    public IPage<ApplyInvestigation> list(ApplyInvestigation applyInvestigation)
    {
        IPage<ApplyInvestigation> page = applyInvestigationService.selectApplyInvestigationList(applyInvestigation);
        return page;
    }

    /**
     * 查询个人申请各个家庭年人均收入数量（饼状图）
     * @return
     */
    @ApiOperation(value = "查询个人申请各个家庭年人均收入数量（饼状图）")
    @GetMapping("/countByAAnnualIncome")
    public List<Map<String ,Object>>countByAAnnualIncome(){
        List<Map<String, Object>> maps = applyInvestigationService.countByAAnnualIncome();
        return maps;
    }

    /**
     * 查询个人申请各个家庭年人总收入数量（柱状图）
     * @return
     */
    @ApiOperation(value = "查询个人申请各个家庭年人总收入数量（柱状图）")
    @GetMapping("/countByTotalIncome")
    public List<Map<String ,Object>>countByTotalIncome() {
        List<Map<String, Object>> maps = applyInvestigationService.countByTotalIncome();
        return maps;
    }

//    public AjaxResult list(ApplyInvestigation applyInvestigation) {
//        List<ApplyInvestigation> list = applyInvestigationService.list();
//        return AjaxResult.success(list);
//
//
//
////        List<ApplyInvestigation> list = applyInvestigationService.selectApplyInvestigationList(applyInvestigation);
////        return getDataTable(list);
//    }

    /**
     * 导出申请调查列表
     */
//    @PreAuthorize("@ss.hasPermi('map:investigation:export')")
//    @Log(title = "申请调查", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ApplyInvestigation applyInvestigation) {
//        List<ApplyInvestigation> list = applyInvestigationService.selectApplyInvestigationList(applyInvestigation);
//        ExcelUtil<ApplyInvestigation> util = new ExcelUtil<ApplyInvestigation>(ApplyInvestigation.class);
//        util.exportExcel(response, list, "申请调查数据");
//    }

    /**
     * 获取申请调查详细信息
     */
    @ApiOperation(value = "获取申请调查详细信息")
//    @PreAuthorize("@ss.hasPermi('map:investigation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {

        return AjaxResult.success(applyInvestigationService.getById(id));
    }

//    /**
//     * 根据姓名获取申请调查详细信息
//     */
//    @ApiOperation(value = "根据姓名获取申请调查详细信息")
//    @PreAuthorize("@ss.hasPermi('map:investigation:query')")
//    @GetMapping(value = "/{name}")
//    public AjaxResult getInfoByName(@PathVariable("name") String name) {
//        return AjaxResult.success(applyInvestigationService.list(Wrappers.<ApplyInvestigation>lambdaQuery().eq(ApplyInvestigation::getName, name)));
//    }

    /**
     * 新增申请调查
     */
    @ApiOperation(value = "新增申请调查表")
//    @PreAuthorize("@ss.hasPermi('map:investigation:add')")
    @Log(title = "申请调查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplyInvestigation applyInvestigation) {
        return toAjax(applyInvestigationService.save(applyInvestigation));
    }

    /**
     * 修改申请调查
     */
//    @PreAuthorize("@ss.hasPermi('map:investigation:edit')")
    @Log(title = "申请调查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplyInvestigation applyInvestigation) {
        return toAjax(applyInvestigationService.updateById(applyInvestigation));
    }

    /**
     * 删除申请调查
     */
//    @PreAuthorize("@ss.hasPermi('map:investigation:remove')")
    @Log(title = "申请调查", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(applyInvestigationService.removeByIds(Arrays.asList(ids)));
    }
}
